﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EZCRS.HCMS.Entity;
using EZCRS.HCMS.SqlClient;

namespace EZCRS.HCMS.Bll
{
    public class BllRatePlan
    {
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="Pid"></param>
        /// <param name="State"></param>
        /// <param name="RoomCode"></param>
        /// <param name="RateCode"></param>
        /// <param name="Page"></param>
        /// <param name="PageSize"></param>
        /// <param name="Rows"></param>
        /// <returns></returns>
        public List<HCRS_Plan> getListByPage(int Pid, int State, int Language, string RoomCode, int Page, int PageSize, out int Rows)
        {

            string strWhere = " property_id = " + Pid.ToString();

            if (!string.IsNullOrEmpty(RoomCode))
                strWhere += " AND roomcode = '" + RoomCode + "'";

            strWhere += " AND languagetype = " + Language.ToString();

            if (State >= 0)
                strWhere += " AND available = " + State.ToString();
            else
                strWhere += " AND available IS NOT NULL";

            return new sql_hcrs_Plan().getListByPage(Page, PageSize, strWhere, out Rows);
        }


        public bool Add(HCRS_Plan obj)
        {
            return new sql_hcrs_Plan().Add(obj);
        }

        public bool Update(HCRS_Plan obj)
        {
            return new sql_hcrs_Plan().Update(obj);
        }

        public HCRS_Plan getItem(int ID)
        {
            return new sql_hcrs_Plan().getItem(ID);
        }

        /// <summary>
        /// 获取价格代码
        /// </summary>
        /// <param name="Pid"></param>
        /// <param name="RateCode"></param>
        /// <param name="Language"></param>
        /// <param name="State"></param>
        /// <returns></returns>
        public List<HCRS_Plan> getPlanByRateCode(int Pid, string RateCode, int Language, int State)
        {

            string strWhere = " property_id = " + Pid.ToString();

            strWhere += " AND plancode LIKE '%-" + RateCode + "'";

            strWhere += " AND languagetype = " + Language.ToString();

            strWhere += " AND available = " + State.ToString();

            return new sql_hcrs_Plan().getall(strWhere);
        }

        /// <summary>
        /// 获取价格计划
        /// </summary>
        /// <param name="Pid"></param>
        /// <param name="PlanCode"></param>
        /// <param name="Language"></param>
        /// <returns></returns>
        public List<HCRS_Plan> getPlan(int Pid, string PlanCode, int Language)
        {

            string strWhere = " property_id = " + Pid.ToString();

            strWhere += " AND plancode = '" + PlanCode + "'";

            strWhere += " AND languagetype = " + Language.ToString();

            return new sql_hcrs_Plan().getall(strWhere);
        }

        /// <summary>
        /// 获取对象
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public HCRS_Season getSeasonPlan(int ID)
        {
            return new sql_hcrs_season().getitem(ID);
        }

        /// <summary>
        /// 获取季节段设置
        /// </summary>
        /// <param name="Pid"></param>
        /// <param name="Page"></param>
        /// <param name="PageSize"></param>
        /// <param name="Rows"></param>
        /// <returns></returns>
        public List<HCRS_Season> getSeasonList(int Pid, int Page, int PageSize, out int Rows)
        {
            string strWhere = " property_id = " + Pid.ToString();


            return new sql_hcrs_season().getListByPage(Page, PageSize, strWhere, out Rows);
        }

        /// <summary>
        /// 保存季节计划
        /// </summary>
        /// <param name="season"></param>
        /// <returns></returns>
        public bool SaveSeasonPlan(HCRS_Season season)
        {
            return new sql_hcrs_season().insertorupdate(season);
        }

        /// <summary>
        /// 删除季节性波段计划
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public bool DeleteSeasonPlan(int ID)
        {
            return new sql_hcrs_season().deleteitem(ID);
        }

    }
}
